package cn.darkhorse.basic.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.darkhorse.basic.mapper.QmsHviMachineMapper;
import cn.darkhorse.basic.domain.QmsHviMachine;
import cn.darkhorse.basic.service.IQmsHviMachineService;

/**
 * hvi机台管理Service业务层处理
 *
 * @author ytq
 * @date 2024-07-18
 */
@Service
public class QmsHviMachineServiceImpl extends ServiceImpl<QmsHviMachineMapper, QmsHviMachine> implements IQmsHviMachineService
{
    @Autowired
    private QmsHviMachineMapper qmsHviMachineMapper;

    /**
     * 查询hvi机台管理
     *
     * @param id hvi机台管理主键
     * @return hvi机台管理
     */
    @Override
    public QmsHviMachine selectQmsHviMachineById(Long id)
    {
        return qmsHviMachineMapper.selectQmsHviMachineById(id);
    }

    /**
     * 查询hvi机台管理列表
     *
     * @param qmsHviMachine hvi机台管理
     * @return hvi机台管理
     */
    @Override
    public List<QmsHviMachine> selectQmsHviMachineList(QmsHviMachine qmsHviMachine)
    {
        return qmsHviMachineMapper.selectQmsHviMachineList(qmsHviMachine);
    }

    /**
     * 新增hvi机台管理
     *
     * @param qmsHviMachine hvi机台管理
     * @return 结果
     */
    @Override
    public int saveQmsHviMachine(QmsHviMachine qmsHviMachine)
    {
        if (qmsHviMachine.getId() == null){
            Long count = lambdaQuery().eq(QmsHviMachine::getHviMachineNumber, qmsHviMachine.getHviMachineNumber()).count();
            if (count>0){
                throw new RuntimeException("机台号重复");
            }
            qmsHviMachine.setCreateTime(DateUtils.getNowDate());

            return qmsHviMachineMapper.insertQmsHviMachine(qmsHviMachine);
        }else{
            Long count = lambdaQuery().eq(QmsHviMachine::getHviMachineNumber, qmsHviMachine.getHviMachineNumber()).ne(QmsHviMachine::getId, qmsHviMachine.getId()).count();
            if (count>0){
                throw new RuntimeException("机台号重复");
            }
            qmsHviMachine.setCreateTime(DateUtils.getNowDate());
            return qmsHviMachineMapper.updateQmsHviMachine(qmsHviMachine);
        }
    }


    /**
     * 批量删除hvi机台管理
     *
     * @param ids 需要删除的hvi机台管理主键
     * @return 结果
     */
    @Override
    public int deleteQmsHviMachineByIds(Long[] ids)
    {
        return qmsHviMachineMapper.deleteQmsHviMachineByIds(ids);
    }

    /**
     * 删除hvi机台管理信息
     *
     * @param id hvi机台管理主键
     * @return 结果
     */
    @Override
    public int deleteQmsHviMachineById(Long id)
    {
        return qmsHviMachineMapper.deleteQmsHviMachineById(id);
    }
}
